package study.member.sungil.oop1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author hiyogils
 *
 */
public class Phone {
	private final int CHARGEMAX = 100;
	private final int CHARGEMIN = 0;
	private String phoneNumber = "";
	private static int maxProductNum = 0;
	private int productNum = 0;
	private int chargeRate =0;
	
	private List<Map> phoneBook;
	
	private final String dial[][] ={
				{"1","2","3"}
				,{"4","5","6"}
				,{"7","8","9"}
				,{"#","0","*"}
			};
	
	{
		setMaxProductNum(maxProductNum);
		this.setPhoneNumber("010" + numberGenerate()+ numberGenerate());
	}
	
	public Phone() {
		phoneBook = new ArrayList<Map>();
	}
	
	public int getChargeRate() {
		return chargeRate;
	}

	public void setChargeRate(int chargeRate) {
		if(chargeRate >= CHARGEMIN && chargeRate < CHARGEMAX){ //충전가능 전기충전
			this.chargeRate = (this.chargeRate + chargeRate) >=  CHARGEMAX ? CHARGEMAX : this.chargeRate + chargeRate;
			System.out.println("충전되었습니다. 현재 " + this.chargeRate + "% 입니다.");
			if(this.chargeRate >= CHARGEMAX){
				this.chargeRate = CHARGEMAX;
				System.out.println("충전 완료되었습니다.");
			}
		}else{
			System.out.println("충전중 오동작 하였습니다.");
			return;
		}
	}

	private String numberGenerate(){
		String num4 = "";
		for(int i=0;i<4;i++){
			int num = (int)(Math.random()*10);
				num4 = num4 + num;
		}
		return num4;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	private void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public int getProductNum() {
		return productNum;
	}

	/*public static int getMaxProductNum() {
		return maxProductNum;
	}*/

	private static void setMaxProductNum(int maxProductNum) {
		Phone.maxProductNum = maxProductNum + 1;
	}

	public void setProductNum(int productNum) {
		this.productNum = productNum;
	}

	public String[][] getDial() {
		return dial;
	}
	
	public void displayDial(){
		String dial[][] = this.getDial();
		for(int i=0;i<dial.length;i++){
			for(int j=0;j<dial[i].length;j++){
				System.out.print(dial[i][j] + " ");
			}
			System.out.println();
		}
		
	}
	
	
	public void addAddress(Map addressIno){
		phoneBook.add(addressIno);
	}

	public List<Map> getPhoneBook() {
		return phoneBook;
	}
	
	public void displayPhoneBook(){
		for(Map phone : phoneBook){
			Iterator<String> it = phone.keySet().iterator();
			String value = "";
			while(it.hasNext()){
				String key = it.next();
				if(phone.get(key) instanceof String){
					value = (String)phone.get(key);	
				}
				System.out.print(key +" : "+ value + "\t");
			}
			System.out.println();
		}
	}
	
	public void sendMassage(String phoneNum , String msg){
		System.out.println(phoneNum + "로 "  + msg + " 전송하였습니다.");
	}
	
	public void call(String phoneNum){
		System.out.println(phoneNum + "로전화를 걸었습니다.");
	}
	
	public void called(String phoneNum){
		System.out.println(phoneNum + "로 전화가 왔습니다.");
	}


	

}
